﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZOVNP.Model.Abstracts;

namespace ZOVNP.Engine
{
    [DomainObject(typeof(IOrder))]
    public partial class Order : IOrder
    {
        private IDomainReference<IUser> _userLocker;
        private IDomainReference<ICustomer> _customerLocker;
        private IDomainCollection<IOrderPart> _orderPartsLocker;

        public Order()
        {
            _userLocker = new SmartReference<Order, User, IUser>(this, UserReference, it => it.UserID);
            _customerLocker = new SmartReference<Order, Customer, ICustomer>(this, CustomerReference, it => it.CustomerID);
            _orderPartsLocker = new SmartCollection<OrderPart, IOrderPart>(this, OrderParts);
        }

        IDomainReference<IUser> IOrder.UserReference
        {
            get { return _userLocker; }
        }

        IDomainReference<ICustomer> IOrder.CustomerReference
        {
            get { return _customerLocker; }
        }

        IUser IOrder.User
        {
            get
            {
                return _userLocker.Value;
            }
            set
            {
                _userLocker.Value = value;
            }
        }

        ICustomer IOrder.Customer
        {
            get
            {
                return _customerLocker.Value;
            }
            set
            {
                _customerLocker.Value = value;
            }
        }

        IDomainCollection<IOrderPart> IOrder.OrderParts
        {
            get { return _orderPartsLocker; }
        }

        public override string ToString()
        {
            return string.Format("{0} - {1}", Number, CreationDate.ToShortDateString());
        }
    }
}
